package com.lvt.example.thinking.in.spring.bean.definition;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * desc：test
 *
 * @author LT
 * @date 2022/3/29
 */
public class ValueLoadDemo {

    @Value("${a.liyun.:false}")
    private Boolean flag;

    public static void main(String[] args) {
        // 创建 BeanFactory 容器
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        // 注册 Configuration Class（配置类）
        applicationContext.register(ValueLoadDemo.class);

        // 启动 Spring 应用上下文
        applicationContext.refresh();

        // 通过 BeanDefinition 注册 API 实现
        ValueLoadDemo bean = applicationContext.getBean(ValueLoadDemo.class);
        if (bean.flag){
            System.out.println("test");
        } else {
            System.out.println("demo");
        }

        // 按照类型依赖查找
        // 显示地关闭 Spring 应用上下文
        applicationContext.close();
    }

    public Boolean getFlag() {
        return flag;
    }

    public void setFlag(Boolean flag) {
        this.flag = flag;
    }
}

